import {useUserStore} from '@/stores/userStore.js'

// 根据用户的主题设置tabbar等信息
const setTheme=()=>{
	const userStore = useUserStore()
	let isDark = false
	if(userStore.userInfo && userStore.userInfo.theme){
		 isDark = userStore.userInfo.theme=='dark'
	}
	// 设置tabBar
	uni.setTabBarStyle({
		color:isDark?'#e6e6e6':"#000000",
		selectedColor:'#13d36a',
		backgroundColor:isDark?'#2e2e2e':'#F8F8F8',
		borderStyle:isDark?'white':'black',
	})
	uni.setTabBarItem({
		index:0,
		text:'聊天',
		iconPath:isDark?'/static/images/chat-dark.png':'/static/images/chat.png',
		selectedIconPath:'/static/images/selectedChat.png',
	})
	uni.setTabBarItem({
		index:1,
		text:'通讯录',
		iconPath:isDark?'/static/images/addressBook-dark.png':'/static/images/addressBook.png',
		selectedIconPath:'/static/images/selectedAddressBook.png',
	})
	uni.setTabBarItem({
		index:2,
		text:'我',
		iconPath:isDark?'/static/images/my-dark.png':'/static/images/my.png',
		selectedIconPath:'/static/images/selectedMy.png',
	})
	
	//设置窗口背景色(不是页面的背景色是uni.showModal的背景色)
	uni.setBackgroundColor({
		backgroundColor:isDark?'#2e2e2e':'#F8F8F8'
	})
	
}

// 当前主题
const nowTheme=()=>{
	const userStore = useUserStore()
	if(userStore.userInfo && userStore.userInfo.theme){
		 return userStore.userInfo.theme
	}else{
		return 'light'
	}
}

// 切换主题
const changeTheme=(val)=>{
	const userStore = useUserStore()
	if(userStore.userInfo && userStore.userInfo.theme){
		userStore.userInfo.theme=val
		// 切换成功后重新设置主题（修改tabbar的样式）
		setTheme()
	}
}


export { setTheme,nowTheme,changeTheme };

